package com.jl.jlapp.mvp.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemChildClickListener;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.GoodsListAdapter;
import com.jl.jlapp.eneity.GoodsListModel;
import com.jl.jlapp.eneity.GoodsListModel.ResultDataBean;
import com.jl.jlapp.eneity.GoodsListModel.ResultDataBean.GoodsSpecificationDetailsBean;
import com.jl.jlapp.eneity.PostModel;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class NoSortGoodsListForNewsActivity extends AppCompatActivity {
    @BindView(R.id.back)
    ImageView back;
    int classificationId;
    GoodsListAdapter goodsListAdapter;
    List<GoodsListModel.ResultDataBean> goodsListModels = new ArrayList();
    private ProgressDialog progressDialog;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.title)
    TextView title;

    public void buildProgressDialog() {
        if (this.progressDialog == null) {
            this.progressDialog = new ProgressDialog(this);
            this.progressDialog.setProgressStyle(0);
        }
        this.progressDialog.setMessage("加载中");
        this.progressDialog.setCancelable(true);
        this.progressDialog.show();
    }

    public void cancelProgressDialog() {
        if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
            this.progressDialog.dismiss();
        }
    }

    public void getGoodsList(int paramInt) {
        Net.get().getGoodsListAmeliorate(1, "", "", "true", Double.valueOf(0.0D), Double.valueOf(0.0D), "all", paramInt)
                .compose(Transformer.<GoodsListModel>switchSchedulers())
                .subscribe(new CommonObserver<GoodsListModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(GoodsListModel goodsListModel) {

                    }
                });
    }

    public void insertShoppingCart(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3, Integer paramInteger4) {
        Net.get().insertShoppingCart(paramInteger1.intValue(), paramInteger2.intValue(), paramInteger3.intValue(), paramInteger4.intValue(), 0, "")
                .compose(Transformer.<PostModel>switchSchedulers())
                .subscribe(new CommonObserver<PostModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(PostModel postModel) {

                    }
                });

    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.no_sort_goods_list_layout);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        this.classificationId = intent.getIntExtra("classificationId", -1);
        String title = intent.getStringExtra("title");
        this.title.setText(title);
        this.back.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                NoSortGoodsListForNewsActivity.this.finish();
            }
        });
        buildProgressDialog();
        if (this.classificationId == -1) {
            Toast.makeText(this, "页面传值出错...", Toast.LENGTH_SHORT).show();
            return;
        }
        getGoodsList(this.classificationId);
    }

    public void setAdapter() {
        this.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        this.goodsListAdapter = new GoodsListAdapter(R.layout.goods_list_item, this.goodsListModels);
        this.recyclerView.setAdapter(this.goodsListAdapter);
        this.goodsListAdapter.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                paramAnonymousInt = Integer.parseInt((String) ((TextView) paramAnonymousView.findViewById(R.id.goods_id)).getText());
                Intent intent = new Intent(NoSortGoodsListForNewsActivity.this, GoodsDetailActivity.class);
                intent.putExtra("goodsId", paramAnonymousInt);
                NoSortGoodsListForNewsActivity.this.startActivity(intent);
            }
        });
        this.goodsListAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            public void onItemChildClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {
                int i = NoSortGoodsListForNewsActivity.this.getSharedPreferences("JLAppData", 0).getInt("userId", 0);
                if (i > 0) {
                    int j = ((GoodsListModel.ResultDataBean) NoSortGoodsListForNewsActivity.this.goodsListModels.get(paramAnonymousInt)).getId();
                    paramAnonymousInt = ((GoodsListModel.ResultDataBean.GoodsSpecificationDetailsBean) ((GoodsListModel.ResultDataBean) NoSortGoodsListForNewsActivity.this.goodsListModels.get(paramAnonymousInt)).getGoodsSpecificationDetails().get(0)).getId();
                    NoSortGoodsListForNewsActivity.this.insertShoppingCart(Integer.valueOf(i), Integer.valueOf(j), Integer.valueOf(paramAnonymousInt), Integer.valueOf(1));
                    return;
                }
                Toast.makeText(NoSortGoodsListForNewsActivity.this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(NoSortGoodsListForNewsActivity.this, LoginActivity.class);
                NoSortGoodsListForNewsActivity.this.startActivity(intent);
            }
        });
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/NoSortGoodsListForNewsActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */